package com.stylefeng.guns.rest.modular.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @ClassName ResponseVo
 * @Description TODO
 * @Author zhaoluowei
 * @Date 2019/9/9  0:14
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@Accessors(chain = true)
public class ResponseVo<M> implements Serializable {

    //返回状态
    private int status;
    //返回信息描述
    private String msg;
    //返回数据实体
    private M data;

    private String imgPre;

    //分页字段
    private int nowPage;
    private int totalPage;

    private ResponseVo() {
    }

    public static <M> ResponseVo success(M m) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setStatus(0);
        responseVo.setMsg("成功");
        responseVo.setData(m);
        return responseVo;
    }

    public static <M> ResponseVo success(String imgPre, M m) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setStatus(0);
        responseVo.setMsg("成功");
        responseVo.setImgPre(imgPre);
        responseVo.setData(m);
        return responseVo;
    }


    public static <M> ResponseVo success(int totalPage,int nowPage, String imgPre, M m) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setStatus(0);
        responseVo.setMsg("成功");
        responseVo.setImgPre(imgPre);
        responseVo.setData(m);
        responseVo.setTotalPage(totalPage);
        responseVo.setNowPage(nowPage);
        return responseVo;
    }


    public static <M> ResponseVo success(String msg) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setStatus(0);
        responseVo.setMsg(msg);
        return responseVo;
    }

    public static <M> ResponseVo serviceFail(String msg) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setStatus(1);
        responseVo.setMsg(msg);
        return responseVo;
    }

    public static <M> ResponseVo serviceException(String msg) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setStatus(999);
        responseVo.setMsg(msg);
        return responseVo;
    }


}
